module.exports = (grunt) ->

  # These plugins provide necessary tasks.
  grunt.loadNpmTasks 'grunt-contrib-clean'
  grunt.loadNpmTasks 'grunt-contrib-concat'
  grunt.loadNpmTasks 'grunt-contrib-uglify'
  grunt.loadNpmTasks 'grunt-contrib-copy'
  grunt.loadNpmTasks 'grunt-contrib-coffee'
  grunt.loadNpmTasks 'grunt-contrib-less'
  grunt.loadNpmTasks 'grunt-contrib-requirejs'
  grunt.loadNpmTasks 'grunt-contrib-watch'

  # Project configuration.
  grunt.initConfig
    pkg: grunt.file.readJSON 'package.json'

    clean:
      app       : 'public/js/app',
      vendors   : ['public/js/vendors.js', 'public/js/vendors.min.js']
      templates : 'public/templates'

    concat:
      options: separator: ';'
      dist:
        src  : [
          'modernizr-2.6.2'
          'vendors/js/require-2.1.9.js'
          'vendors/js/jquery-1.7.2.js'
          # 'vendors/js/jquery.validate-1.11.1.js'
          'vendors/js/jquery.fancybox.js'
          'vendors/js/jquery.jcrop.js'
          # 'vendors/js/jquery.fileupload.js'
          # 'vendors/js/jquery.iframe-transport.js'
          # 'vendors/js/jquery.ui.widget.js'
          # 'vendors/js/jquery.chosen.js'
          'vendors/js/bootstrap-2.3.2.js'
          # 'vendors/js/lodash-2.4.1.js'
          # 'vendors/js/require-text-2.0.10.js'
          # 'vendors/js/backbone-1.1.0.js'
          # 'vendors/js/chaplin-0.12.0.js'
          # 'vendors/js/handlebars-1.3.0.js'
          # 'vendors/js/underscore.string-2.3.0.js'
          # 'vendors/js/typeahead-0.9.3.js'
          # 'vendors/js/meiomask-1.1.13.js'
          'vendors/js/alertify.js'
        ]
        dest : 'vendors/dist/vendors.js'


    uglify:
      vendor:
        src  : 'vendors/dist/vendors.js'
        dest : 'vendors/dist/vendors.min.js'

    copy:
      templates:
        src  : 'templates/**/*'
        dest : 'public/js/app/'
      vendorsJs:
        expand : true
        src    : ['vendors.min.js', 'vendors.js']
        cwd    : 'vendors/dist/'
        dest   : 'public/js/'

    coffee:
      app:
        expand  : true
        cwd     : 'coffee/app'
        src     : '**/*.coffee'
        dest    : 'public/js/app'
        ext     : '.js'

    less:
      banklion:
        options : compress: true
        src     : 'less/banklion.less'
        dest    : 'public/css/banklion.min.css'
      bootstrap :
        options : compress: true
        src     : 'less/bootstrap-3.0.3/less/bootstrap.less'
        dest    : 'public/css/vendor/bootstrap.min.css'

    watch:
      less:
        options : livereload: true
        files   : 'less/**/*.less'
        tasks   : 'less:banklion'
      coffee:
        options : livereload: true
        files   : ['coffee/app/**/*.coffee', 'coffee/main.coffee']
        tasks   : ['clean:app', 'copy:templates', 'coffee']
      html:
        options : livereload: true
        files   : ['index.html', 'templates/**/*.html']
        tasks   : ['clean:templates', 'copy:templates']
      vendors:
        options : livereload: true
        files   : ['public/js/vendors.min.js']

  # Default task.
  grunt.registerTask 'default', [
    'clean'
    # 'concat'
    # 'uglify'
    'copy'
    'coffee'
    'less'
  ]

  grunt.registerTask 'vendors', [
    'concat'
    'uglify'
    'copy:vendorsJs'
  ]
